import { memo, useEffect, useState } from 'react';
import Header from '../../baseUI/header';
import { OrderType } from '../../types/order';
import OrderItem from './cpms/orderItem';
import {useFetchGetOwnOrders} from "../../service/order";

const OwnOrders = memo(() => {
  const [orders,setOrders] = useState<OrderType[]>([]);
  const {data} = useFetchGetOwnOrders();
  useEffect(() => {
    if(data) {
      setOrders(data)
    }
  }, [data]);

  return (
    <>
      <Header title="我的订单" showReturnBtn size="small" />
      {
        orders.map(item => <OrderItem data={item} key={item.id} />)
      }
    </>
  );
});

export default OwnOrders;
